/**
 * File: MaqContigController.java
 * Created by: mhaimel
 * Created on: 6 Jul 2009
 * CVS:  $Id: MaqContigController.java,v 1.1 2009/08/05 15:16:12 mhaimel Exp $
 */
package uk.ac.ebi.curtain.controller.maq.impl;

import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.NotImplementedException;

import uk.ac.ebi.curtain.controller.ParallelController;
import uk.ac.ebi.curtain.controller.SimpleReport;
import uk.ac.ebi.curtain.controller.maq.MaqBean;
import uk.ac.ebi.curtain.controller.maq.MaqContigOutputBean;
import uk.ac.ebi.curtain.management.IControllerReport;
import uk.ac.ebi.curtain.management.InterceptorInfo;
import uk.ac.ebi.curtain.processor.maq.impl.MaqContigProcessor;
import uk.ac.ebi.curtain.utils.file.FileInfo;

/**
 * @author mhaimel
 *
 */
public class MaqContigController extends ParallelController<MaqBean,MaqContigOutputBean, MaqContigProcessor> {
	private Integer iCnt = 0;
	private Set<FileInfo> contigFiles = new HashSet<FileInfo>();

	
	@Override
	public synchronized void handle(MaqBean input, InterceptorInfo info) {
		for(FileInfo fi : input.getContigFiles()){
			if(!contigFiles.contains(fi)){
				++iCnt;
				MaqBean bean = new MaqBean(input);
				bean.getContigFiles().clear();
				bean.getContigFiles().add(fi);
				MaqContigProcessor processor = getContext().getInjector().getInstance(MaqContigProcessor.class);
				processor.setInput(bean);
				submit(processor);
				contigFiles.add(fi);
			}
		}
	}
	
	
	@Override
	protected MaqContigProcessor buildJob(MaqBean input, InterceptorInfo info) {
		throw new NotImplementedException("Should not be called - handle overwritten!!!");
	}

	@Override
	protected IControllerReport getReturnCall() {
		return new SimpleReport("MAQ: Contigs processed: " + iCnt);
	}

}
